Skip to content

Let a SubscribeWalletEvents client intercept a wallet's withdrawals before they are signed - #669

Merged
Jossec101 merged 3 commits into
mainfrom
wallet-events/interceptor
Nov 12, 2026
Merged

Jossec101 merged 3 commits into
mainfrom
wallet-events/interceptor

Conversation

@Jossec101

@Jossec101 Jossec101 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Stack: 3/4 · based on #668 · next #670

What

  • subscribe.intercept_withdrawals = true turns a subscription into a withdrawal interceptor
    • it receives WALLET_EVENT_WITHDRAWAL_DECISION_REQUESTED (destinations, amount, fee rate, RBF links, decision_id, decision_deadline_unix_ms), whatever its event filter
    • it answers on the same call with WithdrawalDecision { decision_id, allow, reason }
  • WithdrawalInterceptorGate (singleton), asked by PerformWithdrawalJob right before signing every withdrawal (UI, gRPC, transfers, hot and cold, RBF bumps and cancellations)
    • no interceptor connected → check skipped
    • all connected interceptors allow → signed and broadcast
    • any block, no answer within WITHDRAWAL_INTERCEPTOR_TIMEOUT_SECONDS (default 60), or an interceptor leaving first → request Rejected with Blocked by integrator '<token>': <reason> (fail closed)
    • a rejected RBF replacement puts the original back to pending confirmation
  • PerformWithdrawalJob's failure path now reverts the original via WithdrawalRequestService.RevertOriginalAsync (clears the reason, checks the replacement actually marked it)
  • Audit rows: WithdrawalInterceptorConnected / Disconnected (token, wallet, IP) and WithdrawalAllowedByIntegrator / WithdrawalBlockedByIntegrator (decision id, interceptors, reason); enum values appended (stored as int, no migration)
  • Half-closing the request stream ends an interceptor's call

Why

  • Integrators need to veto withdrawals (e.g. screening) before NodeGuard signs, with the check skipped when nobody is intercepting

Caveats

  • The gate is in-process: correct for a single NodeGuard instance only; with replicas, an interceptor on another instance is not seen and the check is skipped
  • Each pending decision holds a Quartz worker for up to the timeout
  • Hooked in PerformWithdrawalJob (the only caller of PerformWithdrawal), not in BitcoinService
  • Cold-wallet RBF: the Withdrawals page marks the original replaced after scheduling the job (existing ordering); a block landing before that mark leaves nothing to revert
  • Any valid API token can intercept any wallet, as any token can already request withdrawals; connect/disconnect is audited
  • API withdrawal/broadcast auditing is out of scope (separate work)

Tested

  • Unit: gate (skip, allow, any-block, timeout, disconnect, cancellation, decision matching), PerformWithdrawalJob (skip/allow/block, block not persisted → never signs, not signable → not asked, failure revert), RPC decision routing + audit, hub interceptor APIs
  • E2E added: allow → broadcast and confirm; block → rejected with reason, never in the mempool, never signed; silent → rejected at the deadline (WITHDRAWAL_INTERCEPTOR_TIMEOUT_SECONDS=10 in the e2e compose); blocked bump → original reverted and confirms
  • Full unit suite green locally; E2E not run yet (needs the run-e2e-tests label or a local stack run)

@Jossec101
Jossec101 added this pull request to stack #671 November 11, 2026 14:36
@Jossec101 Jossec101 changed the title feat: let a SubscribeWalletEvents client intercept a wallet's withdrawals before they are signed Let a SubscribeWalletEvents client intercept a wallet's withdrawals before they are signed Nov 11, 2026
@Jossec101
Jossec101 marked this pull request as ready for review November 11, 2026 17:35
@Jossec101
Jossec101 requested a review from RodriFS November 11, 2026 17:35
@Jossec101
Jossec101 force-pushed the wallet-events/interceptor branch from 339cca6 to 93f7a3e Compare November 11, 2026 17:40
Comment thread src/Jobs/PerformWithdrawalJob.cs Resolved
Base automatically changed from wallet-events/subscribe to main November 12, 2026 09:31
…wals before they are signed

- A subscription with intercept_withdrawals gets WALLET_EVENT_WITHDRAWAL_DECISION_REQUESTED (destinations,
  amount, fee rate, RBF links, decision id + deadline) and answers with a WithdrawalDecision on the same call.
- PerformWithdrawalJob asks WithdrawalInterceptorGate before signing every withdrawal, RBF bumps and
  cancellations included. All connected interceptors must allow; a block, no answer within
  WITHDRAWAL_INTERCEPTOR_TIMEOUT_SECONDS (60s) or a disconnect rejects the request with the reason, and a
  rejected replacement puts the original back to pending confirmation. No interceptor: the check is skipped.
- The job's failure path reverts the original through WithdrawalRequestService.RevertOriginalAsync.
- Audit rows for interceptor connect/disconnect and for each allow/block decision.
@Jossec101
Jossec101 force-pushed the wallet-events/interceptor branch from 93f7a3e to 383650e Compare November 12, 2026 09:31
@Jossec101
Jossec101 requested a review from imclvr November 12, 2026 09:31
@Jossec101
Jossec101 enabled stacked auto-merge (squash) November 12, 2026 09:39
@Jossec101
Jossec101 disabled stacked auto-merge November 12, 2026 09:59
@Jossec101
Jossec101 merged commit 08f72e2 into main Nov 12, 2026
6 checks passed
@Jossec101
Jossec101 deleted the wallet-events/interceptor branch November 12, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants